<template>

	<div>
		{{ msg }}
		<img :src="imgurl" alt="" />
		<FooterMsg></FooterMsg>
	</div>
</template>

<script>
	import { Toast } from 'mint-ui'
	import FooterMsg from '../components/FooterMsg'
	import axios from 'axios'
	import { mapState, mapMutations, mapActions } from 'vuex'
	export default {
		name: 'home',
		components: {
			FooterMsg
		},
		data() {
			return {
				msg: '欢迎来到如e伴',
				obj: {},
				imgurl:''
			}
		},
		created() {
			this.INIT_STATE()
			var that = this;
			this.obj = this.getUrlVars(window.location.href)
			console.log(this.obj)
//			this.login({
//				uid:15974
//			})
			axios.get('http://web.skyeducation.cn/getUserinfo.php', {
				params: this.obj
			}).then(function(out) {
				that.msg = out.data;
				var obj=eval('('+out.data+')')
				obj=obj.data
				that.imgurl=obj.uface
				delete obj.education
				that.login({
//					uid:obj.uid,
					uid:15974,
					uface:obj.uface,
					uname:obj.uname
				})
			})
		},
		computed:{
			...mapState(['userlogin'])
		},
		methods: {
			...mapMutations(['INIT_STATE',"USER_LOGIN"]),
			...mapActions(['login']),
			getUrlVars(url) {
				var hash;
				var myJson = {};
				var hashes = url.slice(url.indexOf('?') + 1).split('&');
				var arr = [];
				for(var i = 0; i < hashes.length; i++) {
					hash = hashes[i].split('=');
					if(myJson.hasOwnProperty(hash[0])) {
						myJson[hash[0]] = myJson[hash[0]] + ',' + hash[1]
					} else {
						myJson[hash[0]] = hash[1]
					}
				}
				return myJson;
			}
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
	h1,
	h2 {
		font-weight: normal;
	}
	
	ul {
		list-style-type: none;
		padding: 0;
	}
	
	li {
		display: inline-block;
		margin: 0 10px;
	}
	
	a {
		color: #42b983;
	}
	
	div {
		font-size: 15px;
	}
</style>